home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Problem with arrays
- Date: Tue, 30 Jan 96 13:52:42 GMT
- Organization: none
- Message-ID: <823009962snz@genesis.demon.co.uk>
- References: <4ejtia$6id@sifon.cc.mcgill.ca> <4el775$g6i@phcoms4.seri.philips.nl>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4el775$g6i@phcoms4.seri.philips.nl>
- keijsers@sce.philips.nl "Marc Keijsers" writes:
-
- >>
- >> I'm currently writing a program using tries to store words. For bulding
- > my trie, I have defined the following struct:
- >>
- >>typedef struct nodebox NODEBOX, *TRIE
- >>
- >>struct nodebox{
- >>{ int letters[100];
- >> TRIE subtree[100];
- >>};
- >>
- >>Then, I declare variables as tries in certain functions. But here's the
- > problem: before inserting any letter in the trie, I expect the
- >>
- >>elements in the array letters to be all zeros( '\0' ) like in a normal empty
- > >array. But instead, the elements of this arrays are weird
- >
- >(Please, Please, don't use the word trIe if you mean tree. It makes
- >this story utterly confusing.)
-
- A Trie is a particular form of tree used in things like dictionaries. I
- don't see any evidence that the term was misused here.
-
- >This is completely NORMAL. If you declare an array, its values are
- >undefined. You will have to write a routine which initialises your
- >structure with '/0' (plain '0' will do also).
-
- Static/global variables are always initialised when they are created (at
- program startup in that case), local (auto) function variables are not
- initialised unless given an explicit initialiser in the definition. This
- is true whatever the type of the variable.
-
- >>numbers like 25678. It bothers me since I assume that they are '\0' in my
- > >insert function. I really don't know what's going wrong.
- >>
- >>If you have any idea or solutions, I'd be very graceful if you could e-mail
- > me; >I'm stuck.
-
- Don't assume that they are '\0' in your code, initialise themn when you
- define them or when you first use them.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-